<?php

namespace app\modules\front\controllers;


use app\models\cacheModel\SettingModel;

/**
 * [前台首页]页面展示控制器
 */
class IndexController extends BaseController
{

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class'        => \yii\filters\AccessControl::className(),
                'rules'        => [
                    [ // 必须登录才能访问
                        'actions' => [],
                        'allow'   => true,
                        'roles'   => ['@'],
                    ],
                    [ // 无需登录即可访问 - 空的请保证里面有一个空字符串
                        'actions' => ['index', 'login', 'register'],
                        'allow'   => true,
                        'roles'   => ['?']
                    ]
                ],
                'denyCallback' => function ($rule, $action) {

                    // 未登录检测
                    if (\Yii::$app->user->isGuest) {
                        exit($this->showError('请先登录', 401, [
                            'title' => '您还未登录'
                        ]));
                    }

                    // 其余情况
                    exit($this->showError('该页面暂时无法访问', 403));
                }
            ]
        ];
    }

    /**
     * 首页页面
     * @return mixed
     */
    public function actionIndex()
    {

        return $this->render('index.tpl', []);
    }

    /**
     * 登录页面
     */
    public function actionLogin()
    {

        // 加载是否[Iframe]进来相关样式
        $isIframe = $this->request('isIframe');

        return $this->render('login', [
            'isIframe' => $isIframe
        ]);
    }

    /**
     * 注册页面
     */
    public function actionRegister()
    {

        return $this->render('register', []);
    }
}
